package myself.a009BinaryTree;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author 叶之越
 * Description
 * Date 2021/1/26
 * Time 22:12
 * Mail 739153436@qq.com
 */
public class LevelTraverseTree {
    public static void level(Node head) {
        if (head == null) {
            return;
        }
        Queue<Node> queue = new LinkedList<>();
        queue.add(head);
        while (queue.size() > 0) {
            Node poll = queue.poll();
            System.out.print(poll.value + ",");
            if (poll.left != null) queue.add(poll.left);
            if (poll.right != null) queue.add(poll.right);
        }
    }

    public static class Node {
        public int value;
        public Node left;
        public Node right;

        public Node(int v) {
            value = v;
        }
    }
}
